<template>
	<view>
		<view class="uni-margin-wrap">
			<swiper class="swiper" 
			circular 
			:indicator-dots="indicatorDots" 
			:autoplay="autoplay" 
			:interval="interval"
			:duration="duration">
				<swiper-item v-for="(item, index) in bannerList" :key="index">
					<view class="swiper-item">
						<image :src="item.pictureUrl"></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
		
		<view class="index-inquiry">
			<view class="index-inquiry-main" @click="gotoRouter('/pages-client/hospital/illnessList')">
				<view class="index-inquiry-section">
					<image src="https://cdn.quantifynet.cn/dti/specialist_iccon@2x.png" class="pic2-0"></image>
					<view>查询病症</view>
				</view>
			</view>
			<view class="index-inquiry-main" @click="gotoRouter('/pages-client/cocm/cocmSelect')">
				<view class="index-inquiry-section">
					<image src="https://cdn.quantifynet.cn/dti/inquiry_icon@2x.png" class="pic2-1"></image>
					<view>健康管家</view>
				</view>
			</view>
		</view>
		
		<uv-waterfall ref="waterfall"
			v-model="list"
			:add-time="10"
			:left-gap="leftGap"
			:right-gap="rightGap"
			:column-gap="columnGap"
			@changeList="changeList">
			<!-- 第一列数据 -->
			<template v-slot:list1>
				<view>
					<view class="info-item" v-for="(item, index) in list1" @click="goDetail(item.id)">
						<image :src="item.pictureUrl" mode="aspectFill"></image>
						<view class="name">{{item.title}}</view>
					</view>
				</view>
			</template>
			<!-- 第二列数据 -->
			<template v-slot:list2>
				<view>
					<view class="goods-item" v-for="(item, index) in list2" @click="goGoods(item.id)">
						<image :src="item.thumbUrl" mode="aspectFill"></image>
						<view class="name">{{item.name}}</view>
						<view class="buy-view">
							<view class="sale-num">销量：{{item.saleVolume}}</view>
							<view class="buy">立即购买</view>
						</view>
						<view class="goods-price"><span style="font-size: 24rpx;">￥</span>{{item.salePrice}}</view>
					</view>
				</view>
			</template>
		</uv-waterfall>
	</view>
</template>

<script>
	import { guid } from '@/uni_modules/uv-ui-tools/libs/function/index.js'
	export default {
		
		data() {
			return {
				bannerList:[],
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				lists: [],
				list: [],// 瀑布流全部数据
				list1:[],
				list2:[],
				leftGap: 10,
				rightGap: 10,
				columnGap: 10
			}
		},
		computed: {
			imageStyle(item) {
				return item=>{
					const v = uni.upx2px(750) - this.leftGap - this.rightGap - this.columnGap;
					const w = v/2;
					const rate = w / item.w;
					const h = rate* item.h;
					return {
						width: w + 'px',
						height: h + 'px'
					}
				}
			}
		},
		onShow() {
			this.getData();
			this.getMainGoods();
			this.getBanner();
		},
		onLoad() {
			
		},
		methods: {
			goGoods(id){
				uni.navigateTo({
					url:'/pages-client/store/goodsInfo?id='+id
				})
			},
			goDetail(id){
				uni.navigateTo({
					url:'/pages/goods/detail?id='+id
				})
			},
			// 这点非常重要：e.name在这里返回是list1或list2，要手动将数据追加到相应列
			changeList(e){
				this[e.name].push(e.value);
			},
			getMainGoods(){
				let params = {pageSize:100,isMain:"1"};
				this.$api
					.goodsList({
						params: params
					})
					.then(res => {
						if (res.code == 200) {
							this.list2 = res.result.records;
						}
					});
			},
			getData(){
				let params ={pageSize:100,izReferrer:"1"};
				this.$api.clientQueryArticleList({
					params: params
				}).then(res =>{
					if (res.code == 200) {
						this.list1 = res.result.records;
					}
				})
			},
			getBanner(){
				let params ={};
				this.$api.queryBannerList({
					params: params
				}).then(res =>{
					if (res.code == 200) {
						this.bannerList = res.result;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #f7f7f7;
	}
.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
	}
	.swiper {
		height: 300rpx;
	}
	.swiper-item {
		display: block;
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
	}
	.swiper-list {
		margin-top: 40rpx;
		margin-bottom: 0;
	}
	.uni-common-mt {
		margin-top: 60rpx;
		position: relative;
	}
	.info {
		position: absolute;
		right: 20rpx;
	}
	.uni-padding-wrap {
		width: 550rpx;
		padding: 0 100rpx;
	}
	.index-inquiry {
		padding-top: 32rpx;
		display: flex;
		justify-content: space-between;
		margin: 0 auto 20rpx;
		padding-left: 32rpx;
		padding-right: 32rpx;
	
		.index-inquiry-main {
			height: 180rpx;
			width: 333rpx;
			border-radius: 16rpx;
			background-color: rgba(255, 255, 255, 1);
			box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
			justify-content: space-between;
			align-items: center;
			display: flex;
			padding: 0 30rpx;
			box-sizing: border-box;
	
			.index-inquiry-section {
				width: 270rpx;
				height: 115rpx;
				flex-direction: row;
				display: flex;
				justify-content: space-between;
	
				> image {
					width: 115rpx;
					height: 115rpx;
				}
	
				> view {
					width: 136rpx;
					display: block;
					overflow-wrap: break-word;
					color: rgba(51, 51, 51, 1);
					font-size: 34rpx;
					font-family: PingFangSC-Regular;
					white-space: nowrap;
					line-height: 48rpx;
					text-align: center;
					margin-top: 32rpx;
				}
			}
		}
	}
	.item{
		margin-top: 20rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		padding-left: 10rpx;
		padding-right: 10rpx;
		
	}
	.info-item{
		margin-bottom: 20rpx;
		width: 340rpx;
		height: 480rpx;
		background: #FFFFFF;
		border-radius: 12rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		
		image{
			width: 262rpx;
			height: 262rpx;
			margin-top: 40rpx;
		}
		.name{
			font-family: PingFang-SC, PingFang-SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #333333;
			margin-top: 50rpx;
			width: 300rpx;
		}
	}
	.goods-item{
		width: 340rpx;
		height: 580rpx;
		background: #FFFFFF;
		border-radius: 12rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 20rpx;
		image{
			width: 262rpx;
			height: 262rpx;
			margin-top: 40rpx;
		}
		.name{
			font-family: PingFang-SC, PingFang-SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #333333;
			margin-top: 50rpx;
			width: 300rpx;
		}
		.buy-view{
			display: flex;
			flex-direction: row;
			justify-content: center;
			margin-top: 15rpx;
			justify-content: space-between;
			width: 300rpx;
			align-items: center;
			padding-left: 20rpx;
			padding-right: 20rpx;
			.sale-num{
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
				font-size: 22rpx;
				color: #888888;
			}
			.buy{
				width: 150rpx;
				height: 50rpx;
				background: #DC564A;
				border-radius: 25rpx;
				color: #fff;
				line-height: 50rpx;
				text-align: center;
				font-size: 22rpx;
				font-family: PingFang-SC, PingFang-SC;
				font-weight: 500;
			}
		}
		.goods-price{
			font-family: DINAlternate, DINAlternate;
			font-weight: bold;
			font-size: 36rpx;
			color: #E04234;
			width: 300rpx;
		}
	}
	
</style>
